package org.jeecg.modules.param.fault.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.param.fault.entity.BikeFaultWarn;
import org.jeecg.modules.param.fault.service.IBikeFaultWarnService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.param.fault.vo.BikeFaultCheckRes;
import org.jeecg.modules.param.fault.vo.BikeFaultWarnRes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 设备预警消息
 * @Author: 月月鸟
 * @Date:   2021-06-03
 * @Version: V1.0
 */
@Api(tags="设备预警消息")
@RestController
@RequestMapping("/warn/bikeFaultWarn")
@Slf4j
public class BikeFaultWarnController extends JeecgController<BikeFaultWarn, IBikeFaultWarnService> {
	@Autowired
	private IBikeFaultWarnService bikeFaultWarnService;

	/**
	 * 分页列表查询
	 *
	 * @param bikeFaultWarn
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="设备预警消息-分页列表查询", notes="设备预警消息-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(BikeFaultWarn bikeFaultWarn,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<BikeFaultWarn> queryWrapper = new QueryWrapper<>();
		if (StringUtils.isNotEmpty(bikeFaultWarn.getStationCode())){
			queryWrapper.like("station_code",bikeFaultWarn.getStationCode());
		}
		if (StringUtils.isNotEmpty(bikeFaultWarn.getWarnType())){
			queryWrapper.eq("warn_type",bikeFaultWarn.getWarnType());
		}
		Page<BikeFaultWarn> page = new Page<BikeFaultWarn>(pageNo, pageSize);
		IPage<BikeFaultWarn> pageList = bikeFaultWarnService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	 /**
	  * 分页列表拼接查询
	  *
	  * @param bikeFaultWarn
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @ApiOperation(value="设备预警消息-分页列表拼接查询", notes="设备预警消息-分页列表拼接查询")
	 @GetMapping(value = "/pageList")
	 public Result<?> pageList(BikeFaultWarn bikeFaultWarn,
									@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
									@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
									HttpServletRequest req) {
		 return bikeFaultWarnService.pageList(pageNo,pageSize,bikeFaultWarn);
	 }
	/**
	 *   添加
	 *
	 * @param bikeFaultWarn
	 * @return
	 */
	@AutoLog(value = "设备预警消息-添加")
	@ApiOperation(value="设备预警消息-添加", notes="设备预警消息-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody BikeFaultWarn bikeFaultWarn) {
		bikeFaultWarnService.save(bikeFaultWarn);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param bikeFaultWarn
	 * @return
	 */
	@AutoLog(value = "设备预警消息-编辑",operateType = 3)
	@ApiOperation(value="设备预警消息-编辑", notes="设备预警消息-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody BikeFaultWarn bikeFaultWarn) {
		bikeFaultWarnService.updateById(bikeFaultWarn);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "设备预警消息-通过id删除")
	@ApiOperation(value="设备预警消息-通过id删除", notes="设备预警消息-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		bikeFaultWarnService.removeById(id);
		return Result.OK("删除成功!");
	}

	 /**
	  * 后台转工单
	  * @param bikeFaultWarn
	  * */
	 @AutoLog(value = "设备预警消息-后台转工单")
	 @ApiOperation(value = "后台转工单",notes = "后台转工单")
	 @PostMapping(value = "/goWorkOrder")
	 public Result<?> goWorkOrder(@RequestBody BikeFaultWarnRes bikeFaultWarn){
		 return bikeFaultWarnService.goWorkOrder(bikeFaultWarn);
	 }
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "设备预警消息-批量删除")
	@ApiOperation(value="设备预警消息-批量删除", notes="设备预警消息-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bikeFaultWarnService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="设备预警消息-通过id查询", notes="设备预警消息-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		BikeFaultWarn bikeFaultWarn = bikeFaultWarnService.getById(id);
		if(bikeFaultWarn==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(bikeFaultWarn);
	}

    /**
	  * 导出excel
	  *
	  * @param request
	  * @param bikeFaultWarn
	  */
	 @RequestMapping(value = "/exportXls")
	 public ModelAndView exportXls(HttpServletRequest request, BikeFaultWarn bikeFaultWarn) {
		 return bikeFaultWarnService.exportXls(request,bikeFaultWarn) ;
	 }


}
